package com.cfa.controller;

import com.cfa.model.UmsAdmin;
import com.cfa.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/admin")
public class UmsAdminController {

    @Autowired
    private UmsAdminService umsAdminService;

    @RequestMapping("/login")
    public String login (Model model, String username, String password){
        ModelAndView mav=new ModelAndView();
        UmsAdmin admin=new UmsAdmin();
        admin.setUsername(username);
        admin.setPassword(password);
        UmsAdmin Admin=this.umsAdminService.selectByUsernameAndPassword(admin);
        if(ObjectUtils.isEmpty(Admin)){
            mav.setStatus(HttpStatus.OK);
            mav.addObject("msg","该用户不存在");
            return mav.toString();
        }else{
            mav.addObject("admin",Admin);
        }
        return mav.toString();
    }
}
